<!--质押金管理-->
<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler' :tableObj='$refs.table'>
      <f-search-form-item label='单号' name='depositNo' />
      <f-search-form-item label='单位名称' name='customName' />
      <f-search-form-item label='开始日期' type='range' name='beginDate' />
    </f-search-form>
    <f-table ref='table' rowKey='depositId' :columns='columns' :multiple='false' :operator='operator' :scroll='{x:true}' :params='queryParam' :api='api.deposit'>
          <span slot='fileList' slot-scope='text, record, index'>
        <f-images :value='record.fileList'></f-images>
      </span>
      <span slot='depositState' slot-scope='text, record, index'>
            <a-tag color='pink' v-if='text==0'>未认款</a-tag>
            <a-tag color='#f50' v-if='text==1'>已认款</a-tag>
            <a-tag color='#EE4B2B' v-if='text==2'>已退款</a-tag>
        </span>
      <span slot='paymentState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未提交</a-tag>
            <a-tag color='#108ee9' v-if='text==1' @click='processImg(record)'>审批中</a-tag>
            <a-tag color='#EE4B2B' v-if='text==2'>已审批</a-tag>
       </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='startProcess(record.rkId,"hyAskAmountStartProcessHandler")' v-if='record.rkId && record.paymentState==0'>提交</a>
            <a-divider type='vertical' v-if='record.paymentState==0' />
            <a @click="$refs.drawer.showDrawer(record,'form1')" v-if="record.paymentState==0||record.taskDefinitionKey=='__initiator__'">编辑</a>
            <a-divider type='vertical' v-if='record.paymentState==0' />
            <a-dropdown>
            <a class='ant-dropdown-link'>更多<a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item v-if='record.paymentState==0'>
                <a href='javascript:;' @click='$refs.table.del(record)'>删除</a>
              </a-menu-item>
              <a-menu-item v-if='record.paymentState==2 && record.depositState==1'>
                 <a href='javascript:;' @click='$refs.amount.showDrawer(record)'>退款</a>
              </a-menu-item>
               <a-menu-item v-if='record.paymentState==1'>
                 <a href='javascript:;' @click='deleteProcessInstance(record.processInstanceId,"hySaleManBalanceProcDeleteHandler")'>撤销审批</a>
              </a-menu-item>
               <a-menu-item>
                <a href='javascript:;' @click='printPayment(record)'>打印认款单</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
          </template>

        </span>
    </f-table>
    <deposit-drawer ref='drawer' @success='searchHandler'></deposit-drawer>
    <amount-drawer ref='amount'></amount-drawer>
    <print-modal ref='printModal'></print-modal>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
  </div>
</template>
<script>
import depositDrawer from "./components/deposit_drawer.vue"
import amountDrawer from "./components/amount_drawer.vue"
import ProcessImage from "../../flowable/process/process_image"
import api from "../js/api"
import PrintModal from "../print/print_modal"
import { processMixins } from "@/core/mixins/processMixins"

export default {
  name: "Tab1",
  components: {
    depositDrawer,
    amountDrawer,
    ProcessImage,
    PrintModal
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "添加",
      icon: "plus",
      that: this,
      handler: (table, that) => {
        this.$refs.drawer.showDrawer({}, "form1")
      }
    })
    operator.push({
      name: "删除",
      icon: "delete",
      batch: true,
      handler: function(table) {
        table.remove()
      }
    })
    return {
      api: Object.assign(api, this.api),
      processImageVisible: false,
      //列表初始化查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "单号",
          align: "center",
          width: "130px",
          dataIndex: "depositNo"
        },
        {
          title: "业务员",
          align: "center",
          width: "200px",
          ellipsis: true,
          dataIndex: "saleManName"
        },
        {
          title: "押金金额",
          align: "center",
          width: "100px",
          dataIndex: "payAmount"
        },
        {
          title: "收款银行",
          align: "center",
          ellipsis: true,
          width: "160px",
          dataIndex: "bankName"
        },
        {
          title: "收款账户",
          align: "center",
          width: "160px",
          ellipsis: true,
          dataIndex: "bankNo"
        },
        {
          title: "收款日期",
          align: "center",
          width: "120px",
          dataIndex: "payDate"
        },
        {
          title: "退款金额",
          align: "center",
          width: "80px",
          dataIndex: "refundAmount"
        },
        {
          title: "扣款金额",
          align: "center",
          width: "80px",
          dataIndex: "deductAmount"
        },
        {
          title: "退款日期",
          align: "center",
          width: "100px",
          dataIndex: "refundDate"
        },
        {
          title: "附件",
          align: "center",
          width: "80px",
          dataIndex: "fileList",
          scopedSlots: { customRender: "fileList" }
        },
        {
          title: "认款状态",
          align: "center",
          width: "120px",
          dataIndex: "depositState",
          scopedSlots: { customRender: "depositState" }
        },
        {
          title: "审批状态",
          align: "center",
          dataIndex: "paymentState",
          fixed: "right",
          scopedSlots: { customRender: "paymentState" }
        },
        {
          title: "操作",
          align: "center",
          fixed: "right",
          dataIndex: "action",
          width: "180px",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    //重新提交
    completeTask(deposit) {
      this.http.confirm(this, {
        content: "确认提交审批吗?",
        url: api.tasktodo.complete,
        requestBody: true,
        data: {
          taskId: deposit.taskId
        },
        success: function(me, data) {
          me.$refs.table.refresh()
        }
      })
    },
    //打印退款单
    printPayment(record) {
      this.$refs["printModal"].open(record.depositId, 4, "Other")
    }
  }
}
</script>
